package cn.hema.mapper;

import cn.hema.po.BorrowRecord;
import org.apache.ibatis.annotations.*;

public interface RelationshipMapper {
    @Insert("INSERT INTO record (bookId, borrowerId) " +
            "VALUES (#{bookId}, #{borrowerId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void addRE(BorrowRecord borrowRecord);

    @Select("SELECT COUNT(*) FROM record")
    int get();

    @Select("SELECT COUNT(*) FROM record WHERE bookId = #{bookId} AND borrowerId = #{borrowerId} AND returnDate IS NULL")
    int have(BorrowRecord borrowRecord);

    @Update("UPDATE record SET returnDate = #{returnDate} " +
            "WHERE bookId = #{bookId} AND borrowerId = #{borrowerId} " +
            "AND returnDate IS NULL")
    void back(BorrowRecord borrowRecord);
}
